/***********************************************************************************************
* DISCLAIMER
************************************************************************************************/

/*""FILE COMMENT""******************************************************************************
 * System Name  : FLASH driver software
 * File Name    : w25q_io.h
 * Version      : 
 * Contents     : FLASH driver I/O module common definitions
 * Customer     : Standard
 * Model        : None
 * CPU          : 
 * Compiler     : 
 *              : 
 * OS           : ---
 * Programmer   : 
 * Note         : 
 ***********************************************************************************************
 * History      : Date          Author          Comment
 *""FILE COMMENT END""**************************************************************************/
#ifndef __FLASH_IO_H__
#define __FLASH_IO_H__


/************************************************************************************************/
/*  Definitions                                                                                 */
/************************************************************************************************/
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
/*                         Please define resources of each user system.                         */
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/

/*----------------------------------------------------------------------------------------------*/
/*   Define the software timer value of erase busy waiting.                                     */
/*   If you want to wait till the flash comes to ready status without time out,                 */
/*   comment the definition FLASH_EBUSY_WAIT_TIME.                                              */
/*----------------------------------------------------------------------------------------------*/

#define FLASH_EBUSY_WAIT    (uint16_t)40000     /* Erase busy waiting time   40000* 1ms =   40s */  /** SET **/


/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
/*                              Do not change the following data.                               */
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/


/*----------- Definitions of port control ------------*/
#define FLASH_HI            (uint8_t)0x01               /* Port "H"                             */
#define FLASH_LOW           (uint8_t)0x00               /* Port "L"                             */
#define FLASH_OUT           (uint8_t)0x01               /* Port output setting                  */
#define FLASH_IN            (uint8_t)0x00               /* Port input setting                   */


/*------- Definitions of software timer value --------*/
/* Transmit&receive waiting time */
#define FLASH_WBUSY_WAIT    (uint16_t)18000     /* Write busy waiting time  18000* 1us =  18ms  */  /** SET **/

/* Access time */
#define FLASH_T_WBUSY_WAIT  (uint16_t)MTL_T_1US     /* Write busy completion polling time       */
#define FLASH_T_EBUSY_WAIT  (uint16_t)MTL_T_1MS     /* Erase busy completion polling time       */
#define FLASH_T_DP_WAIT     (uint16_t)MTL_T_4US     /* Deep standby completion waiting time         */
#define FLASH_T_RES_WAIT    (uint16_t)MTL_T_30US    /* Release deep standby completion waiting time */
#define FLASH_T_CS_HOLD     (uint16_t)MTL_T_1US     /* CS stability waiting time                    */
#define FLASH_T_R_ACCESS    (uint16_t)MTL_T_1US     /* Reading start waiting time               */

/*------- Definitions of status register value -------*/
#define FLASH_REG_SRWD      (uint8_t)0x80               /* Status Register Write Disable        */
#define FLASH_REG_BP2       (uint8_t)0x10               /* Block Protect Bit2                   */
#define FLASH_REG_BP1       (uint8_t)0x08               /* Block Protect Bit1                   */
#define FLASH_REG_BP0       (uint8_t)0x04               /* Block Protect Bit0                   */
#define FLASH_REG_WEL       (uint8_t)0x02               /* Write Enable Latch Bit               */
#define FLASH_REG_WIP       (uint8_t)0x01               /* Write In Progress Bit                */


/*- Definitions of byte unit reading writing switch --*//* !!!! Set more than "2" !!!!          */
#define FLASH_BYTE_READ     2                       /* 1byte reading execution judgment bytes   */
#define FLASH_BYTE_WRITE    2                       /* 1byte writing execution judgment bytes   */


/*---- Definitions of resource used for debugging ----*/
#if 0
/* It is invalid for the time being */
#undef FLASH_DMA_ON

/* Repeated use resource definitions */
#define FLASH_DMA_ON                                    /* DMA is used for the data transfer    */
#endif


/*- Definitions of UART overrun error check existence -*/
#if 0
#define FLASH_UART_ORERR                                /* UART overrun error check invalid     */
#endif


/*-------- Definitions of WEL check existence --------*/
#if 1
#define FLASH_WEL_CHK                                   /* WEL check invalid                    */
#endif


/************************************************************************************************/
/*  Unions                                                                                      */
/************************************************************************************************/


/************************************************************************************************/
/*  Structs                                                                                     */
/************************************************************************************************/


/************************************************************************************************/
/*  Externs                                                                                     */
/************************************************************************************************/


/************************************************************************************************/
/*  Macros                                                                                      */
/************************************************************************************************/


/************************************************************************************************/
/*  Prototypes                                                                                  */
/************************************************************************************************/
void SPI_FLASH_Init_Port(uint8_t DevNo);
error_t SPI_FLASH_Read_StsReg(uint8_t DevNo, uint8_t FAR* pStsReg);
error_t SPI_FLASH_Write_StsReg(uint8_t DevNo, uint8_t FAR* pStsReg);
error_t SPI_FLASH_Write_Page(uint8_t DevNo, uint32_t WAddr, uint16_t WCnt, uint8_t FAR* pData);
error_t SPI_FLASH_Read_Memory(uint8_t DevNo, uint32_t RAddr, uint32_t RCnt, uint8_t FAR* pData);
error_t SPI_FLASH_Erase(uint8_t DevNo, uint32_t EAddr, uint8_t Etype);
error_t SPI_FLASH_DPD(uint8_t DevNo);
error_t SPI_FLASH_ReleaseDPD(uint8_t DevNo, uint8_t FAR* pData);
error_t SPI_FLASH_ID(uint8_t DevNo, uint8_t FAR* pData);

#endif /* __FLASH_IO_H__ */

/* End of File */
